<div class="rule-box">
    <ul class="tab">
        <li id="tm_tabs" class="tab_title02"></li>
    </ul>

    <table id="lottery" class="u-table2" style="margin-bottom: 40px;">
        <thead>
            <tr>
                <th colspan="2">玩法</th>
                <th width="120px">赔率</th>
                <th>退水</th>
                <th>单注最低</th>
                <th>单注最高</th>
                <th>单期最高</th>
            </tr>
        </thead>
        <tbody>
        </tbody>
    </table>
</div>
<style type="text/css">
.rule-box .tab {
    width: 100%;
    height: 90px;
    padding: 0px;
    float: none;
    background: none;
    border: 0px;
    color: #000;
    text-align: left;
}
</style>

<script src="../public/all/js/pages/lottery_info.js"></script>
<script>
(function() {
    var games = get_game_list();
    var li = $("#tm_tabs");
    li.empty();
    var l = '<a type="__k__" href="#">__n__</a>';
    for (var i in games) {
        var l2 = l.replace(/__k__/, games[i]);
        l2 = l2.replace(/__n__/, get_game_display_name(games[i]));
        li.append(l2);
    }
    li.append("<div class='clear'></div>");
    $("#tm_tabs a[type='" + game + "']").addClass("on");
    
    var fillLotteryData = function(type) {
        if (type == 'bjpk10' || type == 'zypk10') LotteryInfo.pk10();
        else if (type == 'bjkl8' || type == 'zykl8') LotteryInfo.kl8();
        else if (type == 'cqkl10' || type == 'gdkl10' || type == 'zykl10') LotteryInfo.ten();
        else if (type == 'cqssc' || type == 'xjssc' || type == 'tjssc' || type == 'zyssc' || type == 'ffcqq') LotteryInfo.ssc();
        else if (type == 'jsk3' || type == 'zyk3') LotteryInfo.kuai3();
        else if (type == 'gd115' || type == 'zy115') LotteryInfo.eleven();
        else if (type == 'lhc') LotteryInfo.lhc();
        updateGameLottery(type);
    }
    $("#tm_tabs a").click(function(e) {
        $("#tm_tabs a").removeClass("on");
        $(e.currentTarget).addClass("on");

        fillLotteryData($(e.currentTarget).attr("type"));
    });
    fillLotteryData(game);

    function updateGameLottery(g) {
        startLoading();
        CMD.query_lottery_rate(g, "", function(r) {
            stopLoading();
            var m = {};
            for (var i in r) {
                m[r[i].target] = r[i];
            }
            _fillLottery(g, m);
        });
    }

    function _fillLottery(g, list) {
        if (list.targets) {
            $("#lottery td.max2").html(list.targets.max/100);
        }
        else $("#lottery td.max2").html(0);
        
        var rule = Util.getGameRule(g);
        var map = rule.map;
        for (var k in list) {
            if (isEmpty(map[k])) {
                continue;
            }
            if (list[k].value)
                map[k].rate = list[k].value;
            if (list[k].back)
                map[k].back = list[k].back;
        }

        var trs = $("#lottery tbody tr");
        for (var i = 0; i < trs.length; i++) {
            var k = $(trs[i]).attr("key");
            if (!k) continue;
            if (!map[k]) {
                console.log("不存在类型", k);
                continue;
            }

            $(trs[i]).find(".rate").html(map[k].rate);

            if (!map[k].back) $(trs[i]).find(".back").html("0%");
            else $(trs[i]).find(".back").html(100 * map[k].back + "%");

            if (!map[k].min) $(trs[i]).find(".min").html(0);
            else $(trs[i]).find(".min").html(map[k].min / 100);

            if (!map[k].max) $(trs[i]).find(".max").html(0);
            else $(trs[i]).find(".max").html(map[k].max / 100);
        }
    }
})();
</script>